package file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import data.DataBig;

public class Parsing3ClassesW2InputsBig {
	List<DataBig> list = new ArrayList<DataBig>();
	List<DataBig> pos = new ArrayList<DataBig>();
	List<DataBig> neu = new ArrayList<DataBig>();
	List<DataBig> neg = new ArrayList<DataBig>();
	
	double pavg;
	double navg;
	
	public Parsing3ClassesW2InputsBig(String data, String svm1, String svm2, double margin ) throws IOException {

		BufferedReader dataReader = new BufferedReader(new FileReader(data));
		BufferedReader svm1Reader = new BufferedReader(new FileReader(svm1));
		BufferedReader svm2Reader = new BufferedReader(new FileReader(svm2));
		String line;
		double psum = 0.0;
		int pnum = 0;
		
		double nsum = 0.0;
		int nnum = 0;
		
		int znum = 0;
		
		while((line = dataReader.readLine()) != null){
			String[] field = line.split(",");
			int uid = Integer.parseInt(field[0]);
			int iid = Integer.parseInt(field[1]);
			double rat = Double.parseDouble(field[2]);
			
			DataBig datum = new DataBig(uid, iid, rat);
			list.add(datum);
			
			String line2 = svm1Reader.readLine();
			double margin1 = Double.parseDouble(line2);
			
			if(margin1 > 0) {
				if(margin1 > margin) {
					pos.add(datum);
				}
				else{
					neu.add(datum);
				}
			}
			else {
				String line3 = svm2Reader.readLine();
				double margin2 = Double.parseDouble(line3);
				
				if(margin2 > margin){
					neg.add(datum);
				}
				else {
					neu.add(datum);
				}
			}
		}
		
		dataReader.close();
		svm1Reader.close();
		svm2Reader.close();
	}

	public List<DataBig> getList() {
		return list;
	}

	public List<DataBig> getPos() {
		return pos;
	}

	public List<DataBig> getNeu() {
		return neu;
	}

	public List<DataBig> getNeg() {
		return neg;
	}

	public double getPavg() {
		return pavg;
	}

	public double getNavg() {
		return navg;
	}

}
